﻿using FRMS.Helper;
using FRMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FRMS.DAL
{
    public class DataClearDAL
    {
        public bool DelData(string tablename)
        {
            string strSql = "DELETE FROM " + tablename + " WHERE IsDelete=1";

            return SqlHelper<DataClear>.SqlDelete(strSql);
        }

        public List<DataClear> GetAllTable()
        {
            string strsql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='frms' AND TABLE_TYPE='BASE TABLE'";
            return SqlHelper<DataClear>.SqlList(strsql);
        }

        public int GetAllTableCount()
        {
            string strsql = "SELECT Count(1) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='frms' AND TABLE_TYPE='BASE TABLE'";
            return SqlHelper<DataClear>.SqlScalar(strsql);
        }

        public bool ClearOwner(int projectid)
        {
            string strsql = string.Format(@"DELETE FROM voucher_info WHERE projectID={0};DELETE FROM owner_info WHERE projectID={0}",projectid);
            return SqlHelper<DataClear>.SqlExecute(strsql);
        }

        public bool ClearDevice(int projectid)
        {
            string strsql = string.Format(@"DELETE FROM voucher_info WHERE projectID={0};DELETE FROM owner_info WHERE projectID={0};DELETE FROM device_info WHERE projectID={0}", projectid);
            return SqlHelper<DataClear>.SqlExecute(strsql);
        }

        public bool ClearElevator(int projectid)
        {
            string strsql = string.Format(@"DELETE FROM voucher_info WHERE projectID={0};DELETE FROM owner_info WHERE projectID={0};DELETE FROM device_info WHERE projectID={0};DELETE FROM elevator_info WHERE projectID={0}", projectid);
            return SqlHelper<DataClear>.SqlExecute(strsql);
        }

        public bool ClearRoom(int projectid)
        {
            string strsql = string.Format(@"DELETE FROM voucher_info WHERE projectID={0};DELETE FROM owner_info WHERE projectID={0};DELETE FROM room_info WHERE projectID={0}", projectid);
            return SqlHelper<DataClear>.SqlExecute(strsql);
        }

        public bool ClearBuild(int projectid)
        {
            string strsql = string.Format(@"DELETE FROM voucher_info WHERE projectID={0};DELETE FROM owner_info WHERE projectID={0};DELETE FROM device_info WHERE projectID={0};DELETE FROM room_info WHERE projectID={0};DELETE FROM elevator_info WHERE projectID={0};DELETE FROM building_info WHERE projectID={0}", projectid);
            return SqlHelper<DataClear>.SqlExecute(strsql);
        }
    }
}
